var path = require('path');
//定义了一些文件夹的路径
var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'app');
var LIB_PATH = path.resolve(ROOT_PATH, 'lib');
var BUILD_PATH = path.resolve(ROOT_PATH, 'build');

module.exports = {
    //项目的文件夹 可以直接用文件夹名称 默认会找index.js 也可以确定是哪个文件名字
    entry: {
        app: [path.resolve(APP_PATH, 'index.jsx')],
        requestTest: [path.resolve(APP_PATH, 'requestTest.jsx')],
        //添加要打包在vendors里面的库
    },
    //输出的文件名 合并以后的js会命名为bundle.js
    output: {
        path: BUILD_PATH,
        //注意 我们修改了bundle.js 用一个数组[name]来代替，他会根据entry的入口文件名称生成多个js文件，这里就是(app.js,mobile.js和vendors.js)
        filename: '[name].js'
    },
    //resolve的参数，把jsx这种扩展名添加进去，这样就可以在js中import加载jsx这种扩展名的脚本
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    devtool: 'eval-source-map',
    devServer: {
        historyApiFallback: true,
        hot: true,
        inline: true,
        progress: true,
        port: 7000
    },
    module: {
        loaders: [{
            test: /\.js[x]?$/,
            include: APP_PATH,
            loader: 'babel',
            query: {
                //添加两个presents 使用这两种presets处理js或者jsx文件
                presets: ['es2015', 'react'],
                env: {
                    development: {
                        presets: ["react-hmre"]
                    }
                }
            }
        }, {
            test: /\.scss$/,
            loaders: ['style', 'css?sourceMap', 'sass?sourceMap'],
            include: APP_PATH
        }]
    },
    //添加我们的插件 会自动生成一个html文件
    plugins: [
        /*new HtmlwebpackPlugin({
            title: 'Hello World app'
        })*/
        // Webpack 1.0
        /*    new webpack.optimize.OccurenceOrderPlugin(),
            // Webpack 2.0 fixed this mispelling
            // new webpack.optimize.OccurrenceOrderPlugin(),
            new webpack.HotModuleReplacementPlugin(),
            new webpack.NoErrorsPlugin()*/

    ]
};
